import config from '@/config';


function defaultResolver(data) {
    return data;
}

const Net = (action, params, { method = 'GET', header = {}, config = { type: 'json' } }, resolver = defaultResolver) => {
    return new Promise((resolve, reject) => {
        XUE.net.fetch(action, params, { headers: header, type: config.type })
            .then(res => {
               resolve(resolver(res));
            })
            .catch(err => {
                reject(err);
            });
    });
}

export default Net;
